package com.xuchaotong.zk.server.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.rmi.RemoteException;

/**
 * @author 311633
 * @version 1.0
 * @ClassName:
 * @Description:
 * @date 2017/11/20 11:18
 */
public class ZkServer {

    private static final Logger LOG = LoggerFactory.getLogger(ZkServer.class);

    public static void main(String[] args) throws RemoteException {
        try {

            String path = "/nodeRoot";
            String value = "xuchaotong3";

            ZookeeperMgr.getInstance().init("127.0.0.1:2181", "", false);

            boolean isExist = ZookeeperMgr.getInstance().exists(path);
            if (!isExist) {

                LOG.info(path + " not exist. not update ZK.");

            } else {
                //
                // 通知
                //
                ZookeeperMgr.getInstance().writePersistentUrl(path, value);
            }

        } catch (Exception e) {

            LOG.error(e.toString(), e);
            throw new RemoteException("zk.notify.error", e);
        }
    }
}
